package com.mtnz.njk.Controller;

import com.mtnz.njk.Service.StartImgManageService;
import com.mtnz.njk.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/img")
@CrossOrigin
public class StartImgManageController {
    @Autowired
    StartImgManageService startImgManageService;

    /**
     * 载入页列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @PostMapping("/list")
    public ResponseResult findAllData(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
    return startImgManageService.findAllData(pageNum, pageSize);
    }

    /**
     * 保存图片
     *
     * @param file
     * @param request
     * @return
     */
    @RequestMapping("/saveImg")
    public ResponseResult saveImg(MultipartFile file, HttpServletRequest request) throws Exception {
        return startImgManageService.saveImg(file, request);
    }

    /**
     * 删除图片
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/delImg")
    public ResponseResult delImg(String imgId, HttpServletRequest request, HttpServletResponse response) throws Exception {
        return startImgManageService.delImg(imgId, request, response);
    }

    /**
     * 图片名字和当天日期对比，自动获取图片
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @PostMapping("/selectByDate")
    public ResponseResult selectByDate(HttpServletRequest request, HttpServletResponse response)throws Exception{
        return startImgManageService.selectByDate(request, response);
    }
}
